package net.goutalk.glcs.module.magicapi.controller;


import net.goutalk.glcs.common.annotation.GlcsLog;
import net.goutalk.glcs.common.constant.GlobalConstant;
import net.goutalk.glcs.common.model.result.R;
import net.goutalk.glcs.module.magicapi.service.IMagicApiService;
import net.goutalk.glcs.module.magicapi.vo.MagicApiTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * magic-api模块接口
 * </p>
 *
 * @author tanyujie
 * @since 2022-10-30
 */
@RestController
@RequestMapping(GlobalConstant.MAGICAPI_MODULE_PREFIX)
@Api(value = GlobalConstant.MAGICAPI_MODULE_PREFIX, tags = "magic-api模块接口")
@AllArgsConstructor
public class MagicApiController {

    private final IMagicApiService magicApiService;

    @GetMapping(value = "/tree")
    @ApiOperation("查询所有分组以及api 树结构")
    @GlcsLog(value = "查询所有分组以及api 树结构")
    public R tree(@RequestParam(required = false) String keyword ) {
        List<MagicApiTreeVo> tree = magicApiService.tree(keyword);
        return R.ok(tree);
    }

    @GetMapping(value = "/group/tree")
    @ApiOperation("查询所有树结构分组")
    @GlcsLog(value = "查询所有树结构分组")
    public R groupTree(){
        return R.ok(magicApiService.groupTree());
    }

    @GetMapping(value = "/info")
    @ApiOperation("查询api详情")
    @GlcsLog(value = "查询api详情")
    public R info(@RequestParam String id){
        return R.ok(magicApiService.info(id));
    }

    @GetMapping(value = "/list")
    @ApiOperation("根据分组id 查询所有api")
    @GlcsLog(value = "根据分组id 查询所有api")
    public R list(@RequestParam String groupId){
        return R.ok(magicApiService.list(groupId));
    }

}
